#-*- coding: utf-8 -*-

import math
import sys

class MakeEndsMeet(object):
	def __init__(self, Period):
		self.Period = Period
		self.data = {}
		self.caled = 0 

	def MakeEndsMeet(self):
		if self.caled == 0:
			data_1 = {"Xn":1, "Sn_1":0}
			self.data.setdefault(1, data_1)
			
			for i in range(2,self.Period+1):
				i_data = {}
				i_data["Sn_1"] = self.data[i-1]["Xn"] + self.data[i-1]["Sn_1"]
				i_data["Xn"] = math.ceil(2*i_data["Sn_1"]/3.0)
				self.data.setdefault(i, i_data)
			self.caled = 1
		else:
			pass

	def PrintR(self):
		if len(self.data) != 0:
			print(u"购入期数\t\t\t本期购入\t\t\t本期前共购入")
		for i in range(1,self.Period+1):
			print(str(i) + "\t\t\t\t" + str(self.data[i]["Xn"]) + "\t\t\t\t" + str(self.data[i]["Sn_1"]))


if __name__ == '__main__':

	if(len(sys.argv)<2):
		print(u"请输入期数")
		sys.exit()

	p = int(sys.argv[1])
	print(u"输入参数为："+ sys.argv[1])
	if p > 30:
		print(u"参数过大")
	else:
		period = MakeEndsMeet(p)
		period.MakeEndsMeet()
		period.PrintR()
